/* Allegro */
#include <allegro.h>

#include "../include/input.h"
#include "../include/charloader.h"
#include "../include/sceneloader.h"
#include "../include/collision.h"

void input()
{
    static int counter = 0;

    if(key[KEY_UP])
    {
        if(collision_detect(colX, colY, colTotal, indy->posx, indy->posy - 1) == 1)
        {
            counter++;

            if(counter == 3) {
                indy->posy--;
                counter = 0;
            }

            indy->state = 1;
            indy->direction = 2;
        }
    }

    if(key[KEY_DOWN])
    {
        if(collision_detect(colX, colY, colTotal, indy->posx, indy->posy + 1) == 1)
        {
            counter++;

            if(counter == 3) {
                indy->posy++;
                counter = 0;
            }
            indy->state = 1;
            indy->direction = 3;
        }
    }

    if(key[KEY_LEFT])
    {
        if(collision_detect(colX, colY, colTotal, indy->posx - 1, indy->posy) == 1)
        {
            indy->posx--;
            indy->state = 1;
            indy->direction = 0;
        }
    }

    if(key[KEY_RIGHT])
    {
        if(collision_detect(colX, colY, colTotal, indy->posx + 1, indy->posy) == 1)
        {
            indy->posx++;
            indy->state = 1;
            indy->direction = 1;
        }
    }
}
